package com.diudiutechnology.www.yadiudiu.yadiudiu.mine.MyAdapter;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.diudiutechnology.www.yadiudiu.util.utils.Constant;
import com.diudiutechnology.www.yadiudiu.util.utils.ImgUtils;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;

import java.util.List;


public class BannersAdapter extends PagerAdapter {
    private List<String> adList;
    private Context context;
    private DisplayImageOptions options;
    private ImageLoader imageLoader;
    private int post;//

    public BannersAdapter(Context mContext, List<String> adList, int post) {
        this.adList = adList;
        this.post = post;
        this.context = mContext;
        options = ImgUtils.mImageOptions();
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(ImageLoaderConfiguration.createDefault(mContext));
    }

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    public void addImet(List<String> adList) {
        this.adList = adList;
        notifyDataSetChanged();
    }

    @Override
    public Object instantiateItem(final ViewGroup container, int position) {
        final int pos = position % adList.size();
        ImageView imageView = new ImageView(context);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.FILL_PARENT);
        imageView.setLayoutParams(params);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
//        imageView.setAdjustViewBounds(true);
//        imageView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                Intent intents=new Intent(context,HA_ThepublicdetailsActivity.class);
//                intents.putExtra("pos","5");
//                intents.putExtra("id",adList.get(pos).getId());
//                context.startActivity(intents);
//            }
//        });
//        imageLoader.displayImage(adList.get(pos).getSmeta(), imageView, options);
        if (adList != null && adList.size() > 0) {
            Glide.with(context).load(Constant.HTTP + adList.get(pos)).into(imageView);
        }
        container.addView(imageView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
        return imageView;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }


}
